#include "main.h"

void print_user(void)
{
	printf("====================================user====================================\n");
	printf("命令                                                     \t含义\n");
	printf("mobile login <username> <password>\t\t\t\t登录\n");
	printf("mobile register <username> <password>\t\t\t\t注册\n");
	printf("mobile quit quit quit\t\t\t\t\t\t退出\n");
	printf("============================================================================\n");
}

void print_app(void)
{
	printf("====================================app====================================\n");
	printf("命令                                                     \t含义\n");
	printf("control mac <devname> <devstat>\t\t\t\t\t控制设备\n");
	printf("mobile monitor <username> <password>\t\t\t\t请求获取参数\n");
	printf("mobile monitor_info monitor_info monitor_info\t\t\t进行获取参数\n");
	printf("mobile stop_moninfo_send stop_moninfo_send stop_moninfo_send\t结束获取参数\n");
	printf("mobile quit quit quit\t\t\t\t\t\t退出\n");
	printf("============================================================================\n");
}

int login(int fd)
{
	char buf[size];

	/*等待服务器返回验证结果*/
	usleep(500000);
	bzero(buf,size);
	read(fd,buf,size);
	printf("server>>%s\n",buf);

	if(strncmp(buf,"no",2) == 0)
	{
		printf("登录失败。\n");
		printf("用户名或密码错误。\n");
		close(fd);
		return 1;
	}
	else if(strncmp(buf,"yes",3) == 0)
	{
		printf("登录成功！\n");
		close(fd);
		return 0;
	}
	else
	{
		printf("服务器响应出错。\n");
		close(fd);
		return 1;
	}
}

void regis(int fd)
{
	char buf[size];

	/*等待服务器返回验证结果*/
	usleep(500000);
	read(fd,buf,size);
	printf("server>>%s\n",buf);

	if(strncmp(buf,"NO",2) == 0)
	{
		printf("注册失败。\n");
		printf("该用户已存在。\n");
	}
	else if(strncmp(buf,"YES",3) == 0)
		printf("注册成功！\n");
	else
		printf("服务器响应出错。\n");

	/*断开连接*/
	close(fd);
}

void control(int fd)
{
	char buf[size];

	/*等待服务器返回验证结果*/
	usleep(500000);
	bzero(buf,size);
	read(fd,buf,size);
	printf("server>>%s\n",buf);

	if(strncmp(buf,"SUCCESS",7) == 0)
		printf("设备状态已改变。\n");
	else if(strncmp(buf,"FAIL",4) == 0)
		printf("找不到设备，错误。\n");
	else
		printf("服务器响应出错。\n");

	/*断开连接*/
	close(fd);
}

void req_paras(int fd)
{
	char buf[size];

	/*等待服务器返回验证结果*/
	usleep(500000);
	bzero(buf,size);
	read(fd,buf,size);
	printf("server>>%s\n",buf);

	if(strncmp(buf,"no",2) == 0)
	{
		printf("请求失败。\n");
		printf("登录用户名或密码错误。\n");
	}
	else if(strncmp(buf,"yes",3) == 0)
		printf("请求成功！\n");
	else
		printf("服务器响应出错。\n");

	/*断开连接*/
	close(fd);
}

void get_paras(int fd)
{
	/*等待服务器返回验证结果*/
	usleep(500000);
	bzero(mobilebuf,size);
	read(fd, mobilebuf, size);
	printf("server>>parameters:\n");
	printf("%s\n",mobilebuf);

	/*断开连接*/
	close(fd);
}


